//
//  ViewController.swift
//  SHCountDown
//
//  Created by jiaxing liu on 2019/1/25.
//  Copyright © 2019 jiaxing liu. All rights reserved.
//

import UIKit

class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {

    var cdMgr:SHCountDownListManager?
    
    let dateArray:[Double] = [1588257600,
                              1528344000,
                              1528430400,
                              1588516800,
                              1528603200,
                              1528603221,
                              1578257600,
                              1568344000,
                              1528430400,
                              1568516800,
                              1528603200,
                              1538603221,
                              1528257600,
                              1528344000,
                              1528430400,
                              1528516800,
                              1528603200,
                              1528603221,
                              1528257600,
                              1528344000,
                              1528430400,
                              1528516800,
                              1528603200,
                              1528603221,
                              1528257600,
                              1528344000,
                              1528430400,
                              1528516800,
                              1528603200,
                              1528603221,
                              1528257600,
                              1528344000,
                              1528430400,
                              1528516800,
                              1528603200,
                              1528603221]
    
    lazy var table:UITableView = {
        let tableView = UITableView(frame: self.view.bounds)
        tableView.delegate = self
        tableView.dataSource = self
        
        tableView.register(CountDownCell.self, forCellReuseIdentifier: CountDownCell.tableViewCellIdentifier)
        return tableView
    }()
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        view.addSubview(table)
        cdMgr = SHCountDownListManager(tableView: table, dataArray: dateArray)
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dateArray.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: CountDownCell.tableViewCellIdentifier) as! CountDownCell
        cell.tag = indexPath.row
        cell.dateView.endTime = dateArray[indexPath.row]
        
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 50
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

